// Paket Komnentar dan Manipulasi Komentar
// Visit: http://clever-society.blogspot.com/
// Author Author: Rizal Nurhidayat
// URL: https://plus.google.com/+RizalNurhidayat/about

/* Manipulasi Komentar & Emoticons*/
var $jnoc = jQuery.noConflict();
function repText(id) {
		var a = (document.getElementById(id)) ? document.getElementById(id) : "",
			b = (a !== "") ? a.innerHTML : a,
			c = "http://cs-site.googlecode.com/svn/trunk/emoticon/";
			// Images
			b = b.replace(/<i rel="image">(.*?)<\/i>/ig, "<img class='cm-image' src='$1' alt='loading...' \/>");
			b = b.replace(/\[img\](.*?)\[\/img\]/ig, "<img class='cm-image' src='$1' alt='loading...' \/>");
			// YouTube video
			b = b.replace(/<i rel="youtube">http:\/\/www\.youtube\.com\/embed\/(.*?)<\/i>/ig, "<iframe class='cm-youtube' src='http://www.youtube.com/embed/$1'><\/iframe>");
			b = b.replace(/<i rel="youtube">(http:\/\/youtu\.be\/|http:\/\/www\.youtube\.com\/watch\?v\=)(.*?)<\/i>/ig, "<iframe class='cm-youtube' src='http://www.youtube.com/embed/$2'><\/iframe>");
			b = b.replace(/\[youtube\]http:\/\/www\.youtube\.com\/embed\/(.*?)\[\/youtube\]/ig, "<iframe class='cm-youtube' src='http://www.youtube.com/embed/$1'><\/iframe>");
			b = b.replace(/\[youtube\](http:\/\/youtu\.be\/|http:\/\/www\.youtube\.com\/watch\?v\=)(.*?)\[\/youtube\]/ig, "<iframe class='cm-youtube' src='http://www.youtube.com/embed/$2'><\/iframe>");
			// Code & text block
			b = b.replace(/\[note\](.*?)\[\/note\]/ig,"<div class='note'>$1</div>");
			b = b.replace(/<em rel="note">(.*?)<\/em>/ig,"<div class='note'>$1</div>");
			b = b.replace(/<i rel="code">(.*?)<\/i>/ig, "<code>$1<\/code>");
			b = b.replace(/<i rel="pre">(.*?)<\/i>/ig, "<pre>$1<\/pre>");
			b = b.replace(/<b rel="quote">(.*?)<\/b>/ig, "<blockquote>$1<\/blockquote>");
			b = b.replace(/\[code\](.*?)\[\/code\]/ig, "<code>$1<\/code>");
			b = b.replace(/\[pre\](.*?)\[\/pre\]/ig, "<pre>$1<\/pre>");
			b = b.replace(/\[blockquote\](.*?)\[\/blockquote\]/ig, "<blockquote>$1<\/blockquote>");
			// Safe Link
			b = b.replace(/<i rel="anchor">(.*?)<\/i>/ig,"<a class='allow' href='$1' rel='nofollow'>$1</a>");
			b = b.replace(/\[(link|url)\](.*?)\[\/(link|url)\]/ig,"<a class='allow' href='$2' rel='nofollow'>$2</a>");
			b = b.replace(/\[url\=('|")?(.*?)('|")?\](.*?)\[\/url\]/ig,"<a class='allow' href='$2' rel='nofollow'>$4</a>");
			// Finishing YouTube and Reduce filesize from images that uploaded by Blogger
			b = b.replace(/&amp;feature=[0-9a-zA-Z-_]*/ig, "");
			b = b.replace(/\/s(640|1600)/g, "/s400");
			// Emoticons
			b = b.replace(/\s:(-|)\)/g, " <img class='emo' alt=':)' title=':)' src='" + c + "Smile.png'\/>");
      b = b.replace(/\s;(-|)\)/g, " <img class='emo' alt=';)' title=';)' src='" + c + "Wink.png'\/>");
      b = b.replace(/\s:(-|)\(/g, " <img class='emo' alt=':(' title=':(' src='" + c + "Sad.png'\/>"); 
      b = b.replace(/\s=(-|)\(/g, " <img class='emo' alt='=(' title='=(' src='" + c + "Bad.png'\/>");
      b = b.replace(/\s@@,/g, " <img class='emo' alt='@@,' title='@@,' src='" + c + "Scream.png'\/>");
      b = b.replace(/\s:(-|)(O|o)/ig, " <img class='emo' alt=':O' title=':O' src='" + c + "Scream.png'\/>");
      b = b.replace(/\s&gt;:O/ig, " <img class='emo' alt='&gt;:O' title='&gt;:O' src='" + c + "Angry.png'\/>");
      b = b.replace(/\s:(-|)\@/g, " <img class='emo' alt=':@' title=':@' src='" + c + "Annoyed.png'\/>");
      b = b.replace(/\s:3/ig, " <img class='emo' alt=':3' title=':3' src='" + c + "Curly.png'\/>");
      b = b.replace(/\s:s/ig, " <img class='emo' alt=':s' title=':s' src='" + c + "Embarrassed.png'\/>");
      b = b.replace(/\s:\\/g, " <img class='emo' alt=':&#92;' title=':&#92;' src='" + c + "Concentred.png'\/>");
      b = b.replace(/\s:(-|)\|/ig, " <img class='emo' alt=':|' title=':|' src='" + c + "Thoughful.png'\/>");
      b = b.replace(/\s:\//ig, " <img class='emo' alt=':/' title=':/' src='" + c + "Undecided.png'\/>");
      b = b.replace(/\s:(-|)D/g, " <img class='emo' alt=':D' title=':D' src='" + c + "Happy.png'\/>");
      b = b.replace(/\s(=(-|)D|:ngakak:)/g, " <img class='emo' alt='=D' title='=D' src='" + c + "Laught.png'\/>");
      b = b.replace(/\s(\(|)\^(\_|o|)\^(\)|)/g, " <img class='emo' alt='^_^' title='^_^' src='" + c + "Wonderful.png'\/>");
      b = b.replace(/\s:'\(/g, " <img class='emo' alt=':&#39;(' title=':&#39;(' src='" + c + "Cry.png'\/>");
      b = b.replace(/\sT_T/ig, " <img class='emo' alt='T_T' title='T_T' src='" + c + "Tears.png'\/>");
      b = b.replace(/\sX_X/ig, " <img class='emo' alt='X_X' title='X_X' src='" + c + "Astonish.png'\/>");
      b = b.replace(/\sB(-|)\)/g, " <img class='emo' alt='B)' title='B)' src='" + c + "Cool.png'\/>");
      b = b.replace(/\s:Q/ig, " <img class='emo' alt=':Q' title=':Q' src='" + c + "Emotional.png'\/>");
      b = b.replace(/\s(:(-|)\?|7:\()/g, " <img class='emo' alt=':-?' title=':-?' src='" + c + "Confuse.png'\/>");
      b = b.replace(/\s7:\)/g, " <img class='emo' alt='7:)' title='7:) src='" + c + "Unsure.png'\/>");
      b = b.replace(/\s:(-|)(p|P)/ig, " <img class='emo' alt=':p' title=':p' src='" + c + "Silly.png'\/>");
      b = b.replace(/\s;(-|)(p|P)/ig, " <img class='emo' alt=';p' title=';p' src='" + c + "Sticking.png'\/>");
      b = b.replace(/\s:Oz+/ig, " <img class='emo' alt=':Ozz' title=':Ozz' src='" + c + "Sleep.png'\/>");
      b = b.replace(/\s(\\o\/|:yaya:)/ig, " <img class='emo' alt='&#92;o/' title='&#92;o/' src='" + c + "Excited.png'\/>");
      b = b.replace(/\s&lt;3/ig, " <img class='emo' alt='&lt;3' title='&lt;3' src='" + c + "Heart.png'\/>");
      b = b.replace(/\s&lt;\/3/ig, " <img class='emo' alt='&lt;/3' title='&lt;/3' src='" + c + "Heart%20Brake.png'\/>");
      b = b.replace(/\sO:\)/ig, " <img class='emo' alt='O:)' title='O:)' src='" + c + "Angel.png'\/>");
      b = b.replace(/\s\-(\_|,)\-/g, " <img class='emo' alt='-_-' title='-_-' src='" + c + "Bored.png'\/>");
      b = b.replace(/\s:(\-|)\*/ig, " <img class='emo' alt=':*' title=':*' src='" + c + "Kiss.png'\/>");
      b = b.replace(/\s\o(\_|.)\O/ig, " <img class='emo' alt='o.O' title='o.O' src='" + c + "Crazy.png'\/>");
      b = b.replace(/\s\*(\_|o)\*/ig, " <img class='emo' alt='*_*' title='*_*' src='" + c + "Fantastic.png'\/>");
      b = b.replace(/\s(\^:D|.\_.\+|:idea:)/ig, " <img class='emo' alt='^:D' title='^:D' src='" + c + "Idea.png'\/>");
      b = b.replace(/\s(\(\{\}\)|:inlove:)/ig, " <img class='emo' alt='({})' title='({})' src='" + c + "In%20Love.png'\/>");
      b = b.replace(/\s:W/g, " <img class='emo' alt=':W' title=':W' src='" + c + "Teach.gif'\/>");
      b = b.replace(/\s\(y\)/ig, "<img class='emo' alt='(y)' title='(y)' src='" + c + "Like.png'\/>");
      b = b.replace(/\s\(n\)/ig, "<img class='emo' alt='(n)' title='(n)' src='" + c + "Dislike.png'\/>");
		if (document.getElementById(id)) {
			document.getElementById(id).innerHTML = b;
		}
	} repText('comment-holder'); repText('comment-form'); repText('comment_block'); repText('comment_form'); repText('post-body'); repText('comment_body p'); repText('comment-editor'); repText('post'); repText('emo_box');
   
$jnoc(document.body).on("click", function() {
    $jnoc('.emoKey').remove();
});
$jnoc('.emo').on("click", function(e) {
    $jnoc('.emoKey').remove();
    $jnoc(this).after('<input class="emoKey" type="text" size="2" value=" ' + this.alt + '"/>');
    $jnoc('.emoKey').focus().select();
    e.stopPropagation();
});
	
 /* Konverter */
function cdClear() {
    var wtarea = document.getElementById('codes');
    wtarea.value = '';
    wtarea.focus();
    document.getElementById('cvrt').disabled = false;
}
function cdConvert() {
    var ctarea = document.getElementById('codes'),
        cv = ctarea.value,
        opt1 = document.getElementById('opt1'),
        opt2 = document.getElementById('opt2'),
        opt3 = document.getElementById('opt3'),
        opt4 = document.getElementById('opt4'),
        opt5 = document.getElementById('opt5');
    cv = cv.replace(/\t/g, "    ");
    if (opt1.checked) cv = cv.replace(/&/g, "&amp;");
    if (opt2.checked) cv = cv.replace(/'/g, "&#039;");
    if (opt3.checked) cv = cv.replace(/"/g, "&quot;");
    if (opt4.checked) cv = cv.replace(/</g, "&lt;");
    if (opt5.checked) cv = cv.replace(/>/g, "&gt;");
    if (cv.lastIndexOf('\n') != -1 || cv.length > 40) {
        cv = cv.replace(/^/, "<i rel=\"pre\">");
    } else {
        cv = cv.replace(/^/, "<i rel=\"code\">");
    }
    cv = cv.replace(/$/, "</i>");
    ctarea.value = cv;
    ctarea.focus();
    ctarea.select();
};